﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DBBase;

namespace Business
{
    public partial class weiqistands : DevExpress.XtraEditors.XtraForm
    {
        public weiqistands()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"update StandsEX set STD_SDSGHC={0},
      STD_SDSGCO={1},
      STD_SDSHC={2},
      STD_SDSCO={3},
      STD_ASMCO50={4},
      STD_ASMHC50={5},
      STD_ASMNO50={6},
      STD_ASMCO25={7},
      STD_ASMHC25={8},
      STD_ASMNO25={9},
      STD_LUGM={10},
      STD_LUGNO={11},
      STD_GXSM={12},
      STD_SDSGHCb={13},
      STD_SDSGCOb={14},
      STD_SDSHCb={15},
      STD_SDSCOb={16},
      STD_ASMCO50b={17},
      STD_ASMHC50b={18},
      STD_ASMNO50b={19},
      STD_ASMCO25b={20},
      STD_ASMHC25b={21},
      STD_ASMNO25b={22},
      STD_LUGMb={23},
      STD_LUGNOb={24},
      STD_GXSMb={25},
     STD_fbsxzb={26}
",
                      txtSDSGHC.Text,
                      txtSDSGCO.Text,
                      txtSDSHC.Text,
                      txtSDSCO.Text,
                      txtASMCO50.Text,
                      txtASMHC50.Text,
                      txtASMNO50.Text,
                      txtASMCO25.Text,
                      txtASMHC25.Text,
                      txtASMNO25.Text,
                      txtLUGM.Text,
                      txtLUGNO.Text,
                      txtGXSM.Text,
                      txtSDSGHCb.Text,
                      txtSDSGCOb.Text,
                      txtSDSHCb.Text,
                      txtSDSCOb.Text,
                      txtASMCO50b.Text,
                      txtASMHC50b.Text,
                      txtASMNO50b.Text,
                      txtASMCO25b.Text,
                      txtASMHC25b.Text,
                      txtASMNO25b.Text,
                      txtLUGMb.Text,
                      txtLUGNOb.Text,
                      txtGXSMb.Text,
                      chbxzb.Checked ? 1 : 0);
            if (!objquery.UpdateTable(ssqlex))
            {
                MessageBox.Show("保存失败");
            }  

        }
        private void Getdata()
        {
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"Select * From  StandsEX ");
            DataTable dt = objquery.GetTable(ssqlex);
            for (int i = 0; i < 1; i++)
            {
                txtSDSGHC.Text = dt.Rows[i]["STD_SDSGHC"].ToString().Trim();
                txtSDSGCO.Text = dt.Rows[i]["STD_SDSGCO"].ToString().Trim();
                txtSDSHC.Text = dt.Rows[i]["STD_SDSHC"].ToString().Trim();
                txtSDSCO.Text = dt.Rows[i]["STD_SDSCO"].ToString().Trim();

                txtASMCO50.Text = dt.Rows[i]["STD_ASMCO50"].ToString().Trim();
                txtASMHC50.Text = dt.Rows[i]["STD_ASMHC50"].ToString().Trim();
                txtASMNO50.Text = dt.Rows[i]["STD_ASMNO50"].ToString().Trim();
                txtASMCO25.Text = dt.Rows[i]["STD_ASMCO25"].ToString().Trim();
                txtASMHC25.Text = dt.Rows[i]["STD_ASMHC25"].ToString().Trim();
                txtASMNO25.Text = dt.Rows[i]["STD_ASMNO25"].ToString().Trim();

                txtLUGM.Text = dt.Rows[i]["STD_LUGM"].ToString().Trim();
                txtLUGNO.Text = dt.Rows[i]["STD_LUGNO"].ToString().Trim();

                txtGXSM.Text = dt.Rows[i]["STD_GXSM"].ToString().Trim();     
                //---

                txtSDSGHCb.Text = dt.Rows[i]["STD_SDSGHCb"].ToString().Trim();
                txtSDSGCOb.Text = dt.Rows[i]["STD_SDSGCOb"].ToString().Trim();
                txtSDSHCb.Text = dt.Rows[i]["STD_SDSHCb"].ToString().Trim();
                txtSDSCOb.Text = dt.Rows[i]["STD_SDSCOb"].ToString().Trim();

                txtASMCO50b.Text = dt.Rows[i]["STD_ASMCO50b"].ToString().Trim();
                txtASMHC50b.Text = dt.Rows[i]["STD_ASMHC50b"].ToString().Trim();
                txtASMNO50b.Text = dt.Rows[i]["STD_ASMNO50b"].ToString().Trim();
                txtASMCO25b.Text = dt.Rows[i]["STD_ASMCO25b"].ToString().Trim();
                txtASMHC25b.Text = dt.Rows[i]["STD_ASMHC25b"].ToString().Trim();
                txtASMNO25b.Text = dt.Rows[i]["STD_ASMNO25b"].ToString().Trim();

                txtLUGMb.Text = dt.Rows[i]["STD_LUGMb"].ToString().Trim();
                txtLUGNOb.Text = dt.Rows[i]["STD_LUGNOb"].ToString().Trim();

                txtGXSMb.Text = dt.Rows[i]["STD_GXSMb"].ToString().Trim();
                if (dt.Rows[i]["STD_fbsxzb"].ToString().Trim().ToUpper() == "TRUE")
                {
                    chbxzb.Checked = true;
                }
                else
                {
                    chbxzb.Checked = false;
                }

            }
        }
         private float X;

        private float Y;

        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
                if (con.Controls.Count > 0)
                    setTag(con);
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            foreach (Control con in cons.Controls)
            {

                string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
                float a = Convert.ToSingle(mytag[0]) * newx;
                con.Width = (int)a;
                a = Convert.ToSingle(mytag[1]) * newy;
                con.Height = (int)(a);
                a = Convert.ToSingle(mytag[2]) * newx;
                con.Left = (int)(a);
                a = Convert.ToSingle(mytag[3]) * newy;
                con.Top = (int)(a);
                Single currentSize = Convert.ToSingle(mytag[4]) * Math.Min(newx, newy);
                if (currentSize <= 0)
                {
                    currentSize = 0.1f;
                }
                con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    setControls(newx, newy, con);
                }
            }

        }

        void Form1_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / X;
            float newy = this.Height / Y;
            setControls(newx, newy, this);
            this.Text = this.Width.ToString() + " " + this.Height.ToString();

        }
        private void weiqistands_Load(object sender, EventArgs e)
        {
            this.Resize += new EventHandler(Form1_Resize); this.Resize += new EventHandler(Form1_Resize);

            X = this.Width;
            Y = this.Height;


            setTag(this);
            Form1_Resize(new object(), new EventArgs());//x,y可在实例化时赋值,最后这句是新加的，在MDI时有用
            Getdata();
        }
    }
}